//加载express框架
let express = require("express");
let router = express.Router();

//读取persons.json文件
let fs = require("fs");
let persons = fs.readFileSync(__dirname + "/persons.json", "utf8");
persons = JSON.parse(persons);

//规划路由  加载登录页面
router.get("/login", (req, res) => {
    res.render("login.html")
})

//处理表单数据
router.post("/login", (req, res) => {
    let { tel, pass } = req.body;
    let u = persons.find((item) => {
        return item.username == tel && item.password == pass;
    })
    if (u) {
        res.send("登录成功")
    } else {
        res.send("登录失败")
    }

})

//暴露模块
module.exports = router